# 首页面对象
import time

from selenium.webdriver.common.by import By

from base.ttmp.base_page import BasePage, BaseHandle


class HomePage(BasePage):
    def __init__(self):
        super().__init__()
        # 用户昵称
        self.user_nick = By.CSS_SELECTOR, ".user-name"
        # 内容管理菜单
        self.manage_content = By.XPATH, "//*[text()='内容管理']"
        # 发布文章菜单
        self.publish_article = By.XPATH, "//*[@class='sidebar sidebar-container']/ul/div[2]/li/ul/li[1]"

    # 查找定位用户昵称
    def find_user_nick(self):
        return self.get_element(self.user_nick)

    # 查找内容管理菜单
    def find_manage_content(self):
        return self.get_element(self.manage_content)

    # 查找发布文章菜单
    def find_publish_article(self):
        return self.get_element(self.publish_article)


class HomeHandle(BaseHandle):
    def __init__(self):
        self.home_page = HomePage()

    # 获取用户昵称
    def get_user_info(self):
        return self.home_page.find_user_nick().text

    # 点击 内容管理 菜单
    def click_manage_content(self):
        self.home_page.find_manage_content().click()

    # 点击 发布文章 菜单
    def click_publish_article(self):
        self.home_page.find_publish_article().click()


class HomeProxy:
    def __init__(self):
        self.home_handle = HomeHandle()

    # 获取用户昵称
    def get_nick(self):
        return self.home_handle.get_user_info()

    # 跳转到发布文章页面
    def go_to_publish_page(self):
        time.sleep(1)
        self.home_handle.click_manage_content()  # 点击  内容管理 菜单
        time.sleep(1)
        self.home_handle.click_publish_article()  # 点击 发布文章菜单
